package com.campus.web.controller;


import com.campus.app.service.StudentsService;
import com.campus.commons.entity.Student;
import com.campus.commons.entity.User;
import com.campus.commons.utils.Result;
import com.campus.commons.utils.Tool;
import org.apache.ibatis.plugin.Intercepts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.List;

/**
 * <p>
 * 学生信息表 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentsService studentsService;

    /***
     * 通过姓名验证学生是否存在接口
     * @Author 一行琉璃
     * @param studentName
     * @return
     */
    @GetMapping("/existStudent")
    public Boolean existStudent(String studentName) {
        return studentsService.existStudentByName(studentName);
    }

    /**
     * 获取所有数据接口
     * @author 一行琉璃
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("/all")
    public Result<List<Student>> getAll(int page, int limit) {
        Result<List<Student>> all = studentsService.getAll(page, limit);
        return all;
    }

    /**
     * 复合查询接口
     * @author 一行琉璃
     * @param page
     * @param limit
     * @param student
     * @param start
     * @param end
     * @return
     */
    @PostMapping("/compoundQuery")
    public Result<List<Student>> getAll_By(int page, int limit, Student student, String start, String end) {
        Result<List<Student>> query = studentsService.getCompoundQuery(page, limit, student, start, end);
        return query;

    }

    @PostMapping("/byDeId")
    public Result getStudentsByDeId(Integer deId) {
        return studentsService.getStudentByDeId(deId);
    }

    /**
     * 更新学生信息，接口
     * @author 一行琉璃
     * @param student
     * @param user
     * @return
     */
    @PostMapping("/update")
    public Result update(Student student, User user) {
        Result result = studentsService.updateStudentAndUser(student, user);
        return result;
    }

    /**
     * 删除student 信息 接口
     * @author 一行琉璃
     * @param studentId
     * @param userId
     * @return
     */
    @PostMapping("/delte")
    public Result deleteUserAndStudent(Integer studentId, Integer userId) {
        Result result = studentsService.delUserAndStudent(studentId, userId);
        return result;
    }

    /**
     * 验证身份证接口
     * @author 一行琉璃
     * @param idCard
     * @return
     */
    @PostMapping("/checkIdCard")
    public Boolean checkIdCard(String idCard) {
        Boolean check = studentsService.checkIdCardByIdCad(idCard);
        return check;
    }

    @PostMapping("/add")
    public Result add(User user, Student student) {
        Result result = studentsService.addStudentAndUser(user, student);

        return result;
    }


}




